import { registerMicroApps, addGlobalUncaughtErrorHandler } from "qiankun";

import { MicroConfig } from "./micro-config";

/**
 * 注册微应用
 * 第一个参数 - 微应用的注册信息
 * 第二个参数 - 全局生命周期钩子
 */
export function qiankunInit() {
  console.log("注册");
  registerMicroApps(MicroConfig, {
    // qiankun 生命周期钩子 - 微应用加载前
    beforeLoad: (app: any) => {
      console.log("master before load+++++++++++", app.name);
      return Promise.resolve();
    },
    beforeMount: (app: any) => {
      console.log("master before mount----------", app.name);
      return Promise.resolve();
    },
    // qiankun 生命周期钩子 - 微应用挂载后
    afterMount: (app: any) => {
      console.log("master after mount============", app.name);
      return Promise.resolve();
    },
    afterUnmount: (app: any) => {
      console.log("master after unmount===+++++----", app.name);
      return Promise.resolve();
    }
  });
}

/**
 * 添加全局的未捕获异常处理器
 */
addGlobalUncaughtErrorHandler((event: Event | string) => {
  console.error(event);
});

// 导出 qiankun 的启动函数
// export default start;
